1157번 단어 공부

Day6 6단계 20231024

import java.io.*;
import java.util.*;
import java.util.Map.*;
import java.util.stream.*;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().toUpperCase().split("");
		List<String> listStr = Stream.of(str).collect(Collectors.toList());
		Map<String, Integer> mapStr = Stream.of(str).distinct()
				.collect(Collectors.toMap(i -> i, 
							i -> Collections.frequency(listStr, i.toString())));
		String frqStr = "";
		int frq = 0;
		for (Entry<String, Integer> entry : mapStr.entrySet()) {
			if (entry.getValue() > frq) {
				frqStr = entry.getKey();
				frq = entry.getValue();
			} else if (entry.getValue() == frq) {
				frqStr = "?";
			}
		}
		System.out.println(frqStr);
		br.close();
	}
}